#!/bin/env Rscript

tools_path <- Sys.getenv("tools_path")
data_path <- Sys.getenv("data_path")

dat <- paste(data_path, "/ref/b37/b37.1_Y.chr_length.txt", sep="")

win <- 200000

b37_1_y_chr_len <- read.table(dat, sep="\t")

win_num <- round(b37_1_y_chr_len[,2] / win)

chr0 <- as(b37_1_y_chr_len[,1], "character")

chr <- vector(mode="character")
star <- vector(mode="character")
endd <- vector(mode="character")
index <- 0

for (i in 1:length(win_num)) {

	for (j in 1:(win_num[i]-1)) {
		index = index + 1
		chr[index] <- chr0[i]
		star[index] <- format(win*(j-1)+1, scientific=F)
		endd[index] <- format(win*j, scientific=F)
	}
	index = index + 1
	chr[index] <- chr0[i]
	star[index] <- format(win*j+1, scientific=F)
	endd[index] <- format(b37_1_y_chr_len[i,2], scientific=F)

}


genome_window <- data.frame(chr, star, endd)

write.table(genome_window, file="ge_win0.txt", sep="\t", quote=F, row.names=F, col.names=F)


